<template>
	<view class="agentTodoDetail">
		<form>
			<view class="cu-form-group padding-top-sm">
				<view class="title">姓名</view>
				<input name="name" type="text" disabled v-model="form.name" />
			</view>
			<view class="cu-form-group padding-top-sm">
				<view class="title">手机号</view>
				<input name="tel" type="text" disabled v-model="form.tel" />
			</view>
		</form>
		<view class="flex justify-end">
			<view class="btnContainer"><button class="cu-btn round bg-red" @click="notPassClick">不通过</button></view>
			<view class="btnContainer"><button class="cu-btn round bg-green" @click="passClick">通过</button></view>
		</view>
	</view>
</template>

<script>
import { mapActions } from 'vuex';
export default {
	data() {
		return {
			form: {
				name: '',
				tel: ''
			},
			info: {},
			detail: {}
		};
	},
	onLoad(obj) {
		this.info = this.$store.state.agent.agentTodoCache;
	},
	onReady() {
		console.log(this.info);
		this.generWorkFlow({ ...this.info })
			.then(res => {
				console.log(res);
				if (res.MainTable && res.MainTable[0]) {
					this.form = {
						tel: res.MainTable[0].ShouJiHaoMa,
						name: res.MainTable[0].XingMing
					};
					this.detail = res.MainTable[0];
				}
			})
			.catch(err => {
				console.log(err);
			});
	},
	methods: {
		...mapActions({
			generWorkFlow: 'flow/generWorkFlow',
			staffPass: 'agent/staffPass',
			staffNotPass: 'agent/staffNotPass'
		}),
		notPassClick() {
			let self = this;
			uni.showModal({
				title: '员工审核',
				content: '确定审核不通过？',
				success(res) {
					if (res.confirm) {
						self.staffNotPass({
							fkFlow: self.info.FK_Flow,
							workID: self.info.WorkID
						})
							.then(res => {
								console.log(res);
								if (res && res.code == '000000') {
									uni.showToast({
										title: '操作成功'
									});
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										});
									}, 1500);
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							})
							.catch(err => {
								console.log(err);
								uni.showToast({
									title: '操作失败',
									icon: 'none'
								});
							});
					}
				}
			});
		},
		passClick() {
			let self = this;
			uni.showModal({
				title: '员工审核',
				content: '确定通过审核？',
				success(res) {
					if (res.confirm) {
						self.staffPass({
							fkFlow: self.info.FK_Flow,
							workID: self.info.WorkID,
							tel: self.detail.ShouJiHaoMa,
							wxAppOpenId: self.detail.appOpenId,
							name: self.detail.XingMing,
							parentNo: self.$store.state.agent.agentInfo.No
						})
							.then(res => {
								console.log(res);
								if (res && res.code == '000000') {
									uni.showToast({
										title: '操作成功'
									});
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										});
									}, 1500);
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							})
							.catch(err => {
								console.log(err);
								uni.showToast({
									title: '操作失败',
									icon: 'none'
								});
							});
					}
				}
			});
		}
	}
};
</script>

<style lang="less">
.agentTodoDetail {
	.btnContainer {
		margin: 0 12rpx;
	}
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
}
</style>
